#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>

using namespace std;

int main()
{
	int n, a = 0, b = 1, c = 1;
	int pos = 3;
	cin >> n;
	while (n > c)
	{
		a = b;
		b = c;
		c = a + b;
	}
	cout << min(c-n, n - b) << endl;
	

	return 0;
}